<?php
/**
 * View class definition
 *   
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */
require_once 'interfaces/iView.php';
require_once 'interfaces/iViewRenderer.php';
require_once 'interfaces/iPresenter.php';

/**
 * A simple view that has no particularly helpful functionality
 * for building web pages or forms.
 * @package MutantVole
 * @subpackage Views
 */    
class View extends PropertyObject implements iView {
	
	/**
     * Constructor
	 * @param iViewRenderer|null $renderer
	 */  	
	public function __construct(iViewRenderer $renderer = null) {
		$this->readOnly[] = 'properties';
		
		if ($renderer) {
			$renderer->AttachView($this);
		}
	}

	/**
     * Setter for view properties, encapsulated from View object properties to
	 * avoid possible collisions. View members outside properties array will not
	 * be rendered. 
	 * @param string $property
	 * @param mixed $value
	 */     	
	public function Set($property, $value) {
		$this->properties[$property] = $value;
	}
	
	/**
     * Getter for view properties
	 * @param string $property
	 * @return mixed
	 */   	
	public function Get($property) {
		return $this->properties[$property];
	}
	
	/**
     * Unset a view property
	 * @oaram string $property
	 */  	
	public function Remove($property) {
		unset($this->properties[$property]);
	}
	
	/**
     * Merges an array of values with the existing properties on the view. Does not
	 * overwrite by default
	 * @param array $values
	 * @param bool $overwrite
	 */    	
	public function MergeProperties($values, $overwrite = false) {
		if (count($this->properties) > 0) {
			if ($overwrite) {
				$this->properties = array_merge($this->properties, $values);				
			} else {
				$this->properties = array_merge($values, $this->properties);
			}
		} else {
			$this->properties = $values;
		}
	}
	
	/**
     * properties that will be rendered to the view
	 * @var array
	 */  	
	protected $properties;
}

?>